const Controller = require('egg').Controller;

// 用来更新数据库

class UpgradeController extends Controller {

    async fileDate() {
        const { ctx } = this;
        ctx.model.File.find({}).lean().exec((err, files) => {
            if (err) {
                console.log('出错');
            } else {
                files.forEach( async (file) => {
                    console.log(file.creatDate)
                    await ctx.model.File.findOneAndUpdate({
                        _id: file._id
                    }, {
                        url: file.url,
                        fileName: file.fileName,
                        creator: file.creator,
                        createDate: new Date(file.creatDate),
                    }).lean()
                    .exec((err, doc) => {
                        if (err) {
                            console.log('失败');
                        } else {
                            console.log('成功');
                        }
                    });
                });
            }
        })
    }

}
module.exports = UpgradeController;